<?php 
/////////////////////////////////////////////////////////////////////////////
// 这个文件是 网城创想多用户商城 项目的一部分
//
// Copyright (c) 2007 - 2008 www.shopnc.net
//
// 要查看完整的版权信息和许可信息，请查看源代码中附带的 COPYRIGHT 文件，
// 或者访问 http://www.shopnc.net/ 获得详细信息。
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : product.php   FILE_PATH : home\product.php
 * ....商品展示功能
 *
 * @copyright Copyright (c) 2007 - 2007 www.shopnc.net 
 * @author 网城创想多用户商城开发团队 php_netproject@yahoo.com.cn
 * @package 
 * @subpackage 
 * @version Tue Aug 28 16:09:14 CST 2007
 */
require ("../global.inc.php");

class ShowProduct extends CommonFrameWork{

	/**
	 * 商品对象
	 *
	 * @var obj
	 */
	var $obj_product;
	/**
	 * 商品分类对象
	 *
	 * @var obj
	 */
	var $objProductCate;
	/**
	 * 商铺对象
	 *
	 * @var obj
	 */
	var $obj_shop;
	/**
	 * 会员对象
	 *
	 * @var obj
	 */
	var $obj_member;
	/**
	 * 收货地址对象
	 *
	 * @var obj
	 */
	var $obj_receive;
	/**
	 * 商品订单对象
	 *
	 * @var obj
	 */
	var $obj_product_order;
	/**
	 * 拍卖商品出价对象
	 *
	 * @var obj
	 */
	var $obj_product_bid;
	/**
	 * 网站提醒对象
	 *
	 * @var obj
	 */
	var $obj_remind;
	
	function main(){
		/**
		 * 创建商品对象
		 */
		if (!is_object($this->obj_product)){
			require_once("product.class.php");
			$this->obj_product = new ProductClass();
		}
		/**
		 * 创建验证对象
		 */
		if (!is_object($this->objvalidate)){
			require_once("commonvalidate.class.php");
			$this->objvalidate = new CommonValidate();
		}
		/**
		 * 网站提醒操作
		 */
		if (!is_object($this->obj_remind)){
			require_once('remind.class.php');
			$this->obj_remind = new RemindClass();
		}
		/**
		 * 创建会员对象
		 */
		if (!is_object($this->obj_member)){
			require_once("member.class.php");
			$this->obj_member = new MemberClass();
		}

		/**
		 * 设置模板路径
		 */
		$this->setsubtemplates("home");

		/**
		 * 语言包
		 */
		$this->getlang("product");

		switch ($this->_input['action']){
			case "list":
				$this->_listproduct();
				break;
			case "textlist":
				$this->_listproduct();
				break;
			case "view":
				$this->_viewproduct();
				break;
			case "buy":
				$this->_buyproduct();
				break;
			case "order":
				$this->_orderproduct();
				break;
			case "search":
				//搜索的选项卡：宝贝搜索
				$this->output('InfoSelectorTarget',Common::getTargetMenu("search"));
				$this->_searchproduct();
				break;
			case "compare":
				$this->_compareproduct();
				break;
			case "compareresult":
				$this->_compareproductresult();
				break;
			case "compare_remove":
				$this->_compareremove();
				break;
			case "clean_reviewed":
				$this->_cleanreviewedproduct();
				break;
			case "check_code":
				$this->_check_code();
				break;
			default:
				$this->_listproduct();
				break;
		}
	}

	/**
	 * 商品列表
	 *
	 */
	function _listproduct(){

		if ($this->_input['channel_p_type'] == 1){
			/*页头导航的样式判断*/
			$this->output('search_header_sign',  '4');
		}elseif ($this->_input['channel_p_type'] == 2){
			/*页头导航的样式判断*/
			$this->output('search_header_sign',  '5');
		}

		/**
		 * 初始化分页类
		 */
		require_once("commonpage.class.php");
		$obj_page = new CommonPage();

		/**
		 * 创建商铺对象
		 */
		if (!is_object($this->obj_shop)){
			require_once("shop.class.php");
			$this->obj_shop = new ShopClass();
		}

		if ($this->_input['shopname'] != ""){
			$shop_array = $this->obj_shop->getSomeShopList(30,array('txtShopName'=>$this->_input['shopname']));
			foreach($shop_array as $v){
				$obj_condition[shops] .= $v['member_id'] . ",";
			}
			if (substr($obj_condition[shops],strlen($obj_condition[shops])-1) == ","){
				$obj_condition[shops] = "(" . substr($obj_condition[shops],0,strlen($obj_condition[shops])-1) . ")";
			}
		}

		/**
		 * 取得查询参数
		 */
		if ($this->_input['lang'] == 'zh'){/*分类频道中的关键字搜索*/
			$this->_input['keyword'] = $this->unescape($this->_input['keyword']);
			$this->_input['searchtype'] = 1;
		}
		$obj_condition[key] = $this->_input['keyword'];
		if("" != $this->_input['pcid']){
			$obj_condition[search_cate] = $this->_input['pcid'];
		}else{
			$obj_condition[search_cate] = $this->_input['searchcate'];
		}
		$obj_condition[havetime] = 1;
		if($this->_input['search_name'] != ""){/*搜索栏中的搜索标识*/
			$this->_input['searchtype'] = 1;
		}
		$obj_condition[keygenre] = $this->_input['searchtype'];
		$obj_condition[price_min] = $this->_input['price_min'];
		$obj_condition[price_max] = $this->_input['price_max'];
		$obj_condition[sell_type] = $this->_input['sell_type'];
		/*判断channel_p_type二手闲置类别是否为空*/
		if ($this->_input['channel_p_type'] != ''){
			$obj_condition[p_type] = $this->_input['channel_p_type'];
		}else {
			$obj_condition[p_type] = $this->_input['p_type'];
		}
		$obj_condition[search_place] = $this->_input['search_place'];
		$obj_condition[tf_charge] = $this->_input['tf_charge'];
		$obj_condition[type] = $this->_input['type'];
		$obj_condition[end_time] = $this->_input['end_time'];
		$obj_condition[member] = $this->_input['member'];
		$obj_condition[page] = intval($this->_input['pagelimit']);

		if ($this->_input['order'] == ""){
			$obj_condition[order] = 1;
		}else{
			$obj_condition[order] = $this->_input['order'];
		}
		if ($this->_input['sorttype'] == ""){
			$obj_condition[sorttype] = 1;
		}else{
			$obj_condition[sorttype] = $this->_input['sorttype'];
		}

		require_once("productclass.class.php");
		$obj_search_cate = new ProductCategoryClass();
		$id = 0;
		$deep = 1;
		$search_cate = $obj_search_cate->listCateById($id, $deep);

		/**
		 * 实例化商品订单类
		 */
		if (!is_object($this->obj_product_order)){
			require_once("order.class.php");
			$this->obj_product_order = new ProductOrderClass();
		}
		/**
		 * 更新到期团购商品订单状态
		 */
		$group_product_order_tobe_end_array = $this->obj_product_order->updateProductOrderInCondition();
		/**
		 * 更新到期商品状态
		 */
		$product_tobe_end_array = $this->obj_product->updateProductInCondition();

		/**
		 * 取得商品列表
		 */
		if($obj_condition[page] == ''){
			$obj_condition[page] = 20;
		}

		$obj_page->pagebarnum($obj_condition[page]);
		$product_array = $this->obj_product->getProductList($obj_condition, $obj_page);
		$page_list = $obj_page->show(1);

		/**
		 * 得到店主信息
		 */
		$product_array = $this->obj_member->getSomeMember($product_array,'member_id','member_id,login_name as shopmaster');

		for($i=0;$i<count($product_array);$i++){
			$left_time = $product_array[$i]['p_end_time'] - time();
			$product_array[$i]['left_days'] = intval($left_time / (24*60*60));
			$product_array[$i]['left_hours'] = intval(($left_time % (24*60*60)) / (60*60));
			$product_array[$i]['left_minutes'] = intval((($left_time % (60*60))) / 60);
		}
		/**
		 * 浏览过的宝贝
		 */
		$this->_reviewedproduct();

		/**
		 * 购买过此类商品的人还买过
		 */
		$this->_boughtproduct();

		/**
		 * 根据列表方式选择模板
		 */
		$showpage = $this->_input['showpage'];
		switch ($showpage){
			case "1":
				$page = "product.list";
				break;
			case "2":
				$page = "product.piclist";
				break;
			case "3":
				$page = "product.list";
				break;
			case "digital":/*手机频道*/
			$array = array(3,5,7,8,9,10);
			$page = "digital";

			$obj_page->pagebarnum(2);
			$obj_condition['search_cate'] = '3';
			$lady_product = $this->obj_product->getProductList($obj_condition, $obj_page);
			$this->output('digital_product',$digital_product);
			/*页头导航的样式判断*/
			$this->output('search_header_sign',  '7');
			break;
			case "lady":/*女性频道*/
			$array = array(33,34,32,31,30,28);
			$page = "lady";

			$obj_page->pagebarnum(9);
			$obj_condition['search_cate'] = '33';
			$lady_product = $this->obj_product->getProductList($obj_condition, $obj_page);
			$this->output('lady_product',$lady_product);
			/*页头导航的样式判断*/
			$this->output('search_header_sign',  '8');
			break;
			case "man":/*男人频道*/
			$array = array(35,11,41,10,3,28);
			$page = "man";

			$obj_page->pagebarnum(9);
			$obj_condition['search_cate'] = '35';
			$man_product = $this->obj_product->getProductList($obj_condition, $obj_page);
			$this->output('man_product',$man_product);
			/*页头导航的样式判断*/
			$this->output('search_header_sign',  '9');
			break;
			case "sports":/*运动频道*/
			$array = array(3,11,37,41,35,43);
			$page = "sports";

			$obj_page->pagebarnum(9);
			$obj_condition['search_cate'] = '12';
			$sports_product = $this->obj_product->getProductList($obj_condition, $obj_page);
			$this->output('sports_product',$sports_product);
			/*页头导航的样式判断*/
			$this->output('search_header_sign',  '10');
			break;
			case "life":/*家居频道*/
			$array = array(5,1,3,33,37,41);
			$page = "life";

			$obj_page->pagebarnum(9);
			$obj_condition['search_cate'] = '17';
			$life_product = $this->obj_product->getProductList($obj_condition, $obj_page);
			$this->output('life_product',$life_product);
			/*页头导航的样式判断*/
			$this->output('search_header_sign',  '11');
			break;
			case "baby":/*母婴频道*/
			$array = array(41,1,3,33,37,41);
			$page = "baby";

			$obj_page->pagebarnum(9);
			$obj_condition['search_cate'] = '39';
			$baby_product = $this->obj_product->getProductList($obj_condition, $obj_page);
			$this->output('baby_product',$baby_product);
			/*页头导航的样式判断*/
			$this->output('search_header_sign',  '12');
			break;
			case "game":/*游戏频道*/
			$array = array(41,1,3,33,37,41);
			$page = "game";

			$obj_page->pagebarnum(9);
			$obj_condition['search_cate'] = '14';
			$game_product = $this->obj_product->getProductList($obj_condition, $obj_page);
			$this->output('game_product',$game_product);
			/*页头导航的样式判断*/
			$this->output('search_header_sign',  '13');
			break;
			default:
				$page = "product.list";
				break;
		}

		/**
		 * 取分类频道中页头的类别
		 */
		if (is_array($array)){
			$product_class = $obj_search_cate->getProductClass();
			foreach ($array as $v){
				$product_class[$v-1]['class_array'] = $obj_search_cate->getClassArray($product_class,$v);
				$class_array[] = $product_class[$v-1];
			}
		}
		/**
		 * 输出到页面模板
		 */
		$this->output('class_array',$class_array);
		$this->output("site_url", $this->_configinfo['websit']['site_url']);
		$this->output("page_list", $page_list);
		$this->output("search_cate", Common::showForm_Select2("searchcate", "", "", $search_cate));
		$this->output('category_array',$search_cate);/*分类列表*/
		$this->output("product_array", $product_array);
		$this->_input['sorttype'] = intval(1-$this->_input['sorttype']);
		$this->output("product_condition",$this->_input);
		$this->showpage($page);
	}
	/**
	 * 商品查看页面
	 *
	 */
	function _viewproduct(){
		$p_id = $this->_input['pid'];
		$this->objvalidate->validateparam = array(
		array("input"=>$this->_input["pid"],"require"=>"true","message"=>$this->_lang['errProductId']));
		$error = $this->objvalidate->validate();
		if($error != ""){
			echo $error;
		}else{
			/**
			 * 取得商品信息
			 */
			$product_row = $this->obj_product->getProductRow($p_id);

			/**
			 * 取得商品分类树枝
			 */
			$product_cate = $product_row['pc_id'];
			if (!is_object($this->obj_product_cate)){
				require_once("productclass.class.php");
				$this->obj_product_cate = new ProductCategoryClass();
			}
			$ProductClassArray = $this->obj_product_cate->getProductCateArray();
			$cate_path = $this->obj_product_cate->get_path($ProductClassArray, $product_cate);
			/**
			 * 取得商品属性
			 */
			require_once("attribute.class.php");
			$obj_product_attribute = new AttributeClass();
			$pcid = $product_row['pc_id'];
			$product_attribute = $obj_product_attribute->getAttributeList($pcid);
			if(count($product_attribute)>0){
				$have_attribute = 1;
				$product_attribute_content = $obj_product_attribute->getAttributeWithContentList($pcid);
			}
			$attribute_condition_str = " and p_id = '" . $p_id . "'";
			$product_have_attribute = $this->obj_product->getProductAttribute($attribute_condition_str, $obj_page);

			$i=0;
			if(is_array($product_have_attribute)){
				foreach ($product_have_attribute as $key => $value){

					$ac_content = explode(',', $value[pac_content]);
					foreach ($ac_content as $k => $v){
						$pac_attribute[$i] = $v;
						$i++;
					}
				}
			}

			if(is_array($product_attribute_content)){
				foreach ($product_attribute_content as $key => $value){
					foreach ($value as $k => $v){
						if(is_array($pac_attribute) && in_array($v[ac_id], $pac_attribute)){
							$product_attribute_content[$key][$k][ischecked] = 1;
						}

					}
				}
			}

			/**
			 * 取得出价记录
			 */
			if (!is_object($this->obj_product_order)){
				require_once("order.class.php");
				$this->obj_product_order = new ProductOrderClass();
			}
			/**
			 * 实例化分页类
			 */
			if(!is_object($this->obj_page)){
				require_once("commonpage.class.php");
				$this->obj_page = new CommonPage();
			}

			/**
			 * 取得卖家资料
			 */
			$seller_info = $this->obj_member->getMemberInfo(array("id"=>$product_row['member_id']),'member_id,login_name,sale_score,buy_score,regist_time');
			/**
			 * 得到卖家好评率
			 */
			if (!is_object($this->obj_member_score)){
				require_once("score.class.php");
				$this->obj_member_score = new ScoreClass();
			}
			$seller_info['s_rate'] = $this->obj_member_score->getScorePercent($product_row['member_id'],"s");
			$seller_info['b_rate'] = $this->obj_member_score->getScorePercent($product_row['member_id'],"b");

			/**
			 * 商品购买记录
			 */
			if("0" != $product_row['p_sell_type']){
				$product_row['p_cur_price'] = $product_row['p_price'];
				/**
		 	 	* 限定条件
		 	 	*/
				$obj_condition[p_code] = $p_id;
				$obj_condition[order] = 1;
				/**
			 	* 取得订单列表
			 	*/
				$this->obj_page->pagebarnum(30);
				$product_order_array = $this->obj_product_order->getProductOrderList($obj_condition, $this->obj_page);

				/**
		 		* 得到买家信息
			    */
				$product_order_array = $this->obj_member->getSomeMember($product_order_array,'buyer_id','member_id,login_name as buyer_nick');

				if(is_array($product_order_array)){
					foreach ($product_order_array as $key => $value){
						$product_order_array[$key]['state'] = "2";
					}
				}
				/**
			 	* 订单分页
			 	*/
				$page_list = $this->obj_page->show(1);
			}
			/**
			 * 拍卖出价记录
			 */
			if("0" == $product_row['p_sell_type']){

				if (!is_object($this->obj_product_bid)){
					require_once("bid.class.php");
					$this->obj_product_bid = new BidClass();
				}
				$obj_bid_condition[p_code] = $p_id;
				$obj_bid_condition[order] = 2;
				/**
				 * 如果当前还未有人出价，显示底价
				 */
				if("0" == $product_row['p_cur_price'] || "" == $product_row['p_cur_price']){
					$product_row['p_cur_price'] = $product_row['p_price'];
				}

				/**
			 	* 取得竞拍出价列表
			 	*/
				$product_bid_array = $this->obj_product_bid->getProductBidList($obj_bid_condition, $obj_bid_page);

				/**
		 		* 得到买家信息
			    */
				$product_order_array = $this->obj_member->getSomeMember($product_bid_array,'bid_member_id','member_id,login_name as buyer_nick');

				if(is_array($product_bid_array)){
					//					$product_order_array = array();
					foreach ($product_bid_array as $key => $value){
						$product_order_array[$key]['unit_price'] = $value['bid_price'];
						$product_order_array[$key]['buy_num'] = $value['bid_count'];
						$product_order_array[$key]['sold_time'] = $value['bid_time'];
						$product_order_array[$key]['state'] = $value['bid_state'];
					}
				}

			}

			/**
			 * 剩余时间计算
			 */
			$left_time = $product_row['p_end_time'] - time();
			$product_row['left_days'] = intval($left_time / (24*60*60));
			$product_row['left_hours'] = intval(($left_time % (24*60*60)) / (60*60));
			$product_row['left_minutes'] = intval((($left_time % (60*60))) / 60);

			if("2" == $product_row['p_sell_type']){
				$product_row['less_count'] = $product_row['p_group_mincount'] - $product_row['p_sold_num'];
			}


			/**
			 * 更新商品浏览次数
			 */
			$update_product['p_code'] = $p_id;
			$update_product['txtViewNum'] = 1;
			$update_product_view_num = $this->obj_product->updateProductViewNum($update_product);

			/**
			 * 写进 浏览过的宝贝 cookie名称 product_viewed
			 */
			$this->setReviewed($product_row['p_code']);

			/**
			 * 商品留言信息
			 */
			require_once("productmessage.class.php");
			$obj_message = new ProductMessageClass();
			$message_array = $obj_message->getMessage($page,$product_row['p_id']);
			//print_r( $_SESSION['s_login']);
			$product_row['p_type_name'] = $this->_b_config['p_type'][$product_row['p_type']];
			
			$p_url = "../".$product_row['p_pic'];
			$key = "3irjklsd8432uisdklvr892348";
			$pURL = Common::encodeStr($p_url,$key);
			$this->output('pURL',$pURL);
			
			$this->output("ses_login", $_SESSION['s_login']);   //登陆信息
			$this->output("page_list", $page_list);

			$this->output("product_order_array", $product_order_array);

			$this->output("product_row", $product_row);
			$this->output("PathLinks", $cate_path);
			$this->output("message_array", $message_array);   //商品留言
			$this->output("seller_info", $seller_info);		//商家信息
			$this->output("have_attribute", $have_attribute);
			$this->output("product_attribute", $product_attribute);
			$this->output("product_attribute_content", $product_attribute_content);
			$this->output("product_have_attribute", $pac_attribute);
			$this->showpage("product.view");
		}

	}
	/**
	 * 商品搜索页面
	 *
	 */
	function _searchproduct(){
		/**
		 * 创建商品分类对象
		 */
		if (!is_object($this->objProductCate)){
			require_once ("productclass.class.php");
			$this->objProductCate = new ProductCategoryClass();
		}
		$ProductCateArray = $this->objProductCate->getOneLevelClass($this->objProductCate->listCateById($id, $deep),0);
		//print_r($ProductCateArray);
		$this->output('ProductCateArray',$ProductCateArray);
		$this->showpage("product.search");
	}
	/**
	 * 商品购买页面
	 *
	 */
	function _buyproduct(){
		/**
		 * 判断是否登陆
		 */
		$this->isMember();

		if($_SESSION['s_login']['id']==$this->_input["seller_id"]){
			$this->redirectPath("error","",$this->_lang['errBuyOwnProduct']);
		}
		if (!is_object($this->obj_receive)){
			require_once("receive.class.php");
			$this->obj_receive = new ReceiveClass();
		}
		$seller_info = $this->obj_member->getMemberInfo(array("id"=>$this->_input['seller_id']),'login_name');
		$receive_array = $this->obj_receive->getReceive($_SESSION['s_login']['id']);

		/**
		 * 拍卖的情况，获取下次竞拍出价价格
		 */
		if("0" == $this->_input['auction_type']){

			if("" != $this->_input['buy_now']){

				/*判断是否使用系统自定义加价幅度，1为使用*/
				if($this->_input['p_system_step'] == "1"){
					if (!is_object($this->obj_product_bid)){
						require_once("bid.class.php");
						$this->obj_product_bid = new BidClass();
					}
					$increment['high_bid'] = $this->_input['buy_now'];
					$increment_row = $this->obj_product_bid->getIncrementList($increment);
				}else{
					$increment_row['increment'] = $this->_input['p_price_step'];
				}

				$this->_input['min_price'] = $this->_input['buy_now'] + $increment_row['increment'];
			}else{
				$this->_input['buy_now'] = $this->_input['old_price'];
			}
		}
		
		$this->output('receive_array',$receive_array);
		$this->output("p_code", $this->_input['item_id']);
		$this->output("pc_id", $this->_input['pc_id']);
		$this->output("sell_type", $this->_input['auction_type']);
		$this->output("p_name", $this->_input['title']);
		$this->output("member_id", $this->_input['seller_id']);
		$this->output("seller_nick", $seller_info['login_name']);
		$this->output("p_transfee_charge", $this->_input['who_pay_ship']);
		$this->output("buy_price", $this->_input['buy_now']);
		$this->output("min_price", $this->_input['min_price']);
		$this->output("step_price", $increment_row['increment']);
		$this->output("p_group_mincount", $this->_input['min_count']);
		$this->output("p_sold_num", $this->_input['p_sold_num']);
		$this->output("p_storage", $this->_input['count']);
		$this->output("p_pic", $this->_input['photo_url']);
		$this->output("p_region", $this->_input['region']);
		$this->output("tf_py", $seller_info['tf_py']);
		$this->output("tf_kd", $seller_info['tf_kd']);
		$this->output("tf_ems", $seller_info['tf_ems']);
		$this->output("top_cate", $this->_input['chboxPid']);
		$this->showpage("product.buy");

	}
	/**
	 * 商品购买提交
	 *
	 */
	function _orderproduct(){
		/**
		 * 验证表单信息
		 */
		if("" == $this->_input["txtTfFee"]){
			$this->_input["txtTfFee"] = 0;
		}
		$this->objvalidate->validateparam = array(
		array("input"=>$this->_input["txtSellerId"],"require"=>"true","validator"=>"Number","message"=>$this->_lang['errSellerId']),
		array("input"=>strtoupper($this->_input['checkcode']),"require"=>"true","validator"=>"Compare","operator"=>"==","to"=>strtoupper($_SESSION['seccode']),"message"=>$this->_lang['errProductMCode']),
		array("input"=>$this->_input["txtPname"],"require"=>"true","message"=>$this->_lang['errPname']),
		array("input"=>$this->_input["txtPcode"],"require"=>"true","message"=>$this->_lang['errPcode']),
		array("input"=>$this->_input["txtUnitPrice"],"require"=>"true","validator"=>"Currency","message"=>$this->_lang['errUnitPrice']),
		array("input"=>$this->_input["txtBuyNum"],"require"=>"true","validator"=>"Number","message"=>$this->_lang['errBuyNum']),
		array("input"=>$this->_input["txtTfFee"],"validator"=>"Currency","message"=>$this->_lang['errTfFee']));
		
		$error = $this->objvalidate->validate();

		if($error != ""){
			echo $error;
			exit;
		}else{

			/**
			 * 收货地址关联的处理
			 */
			if("" != $this->_input["checkaddr"]){
				$this->_input["txtReceiveId"] = $this->_input["daddr"];
			}else{

				if (!is_object($this->obj_receive)){
					require_once("receive.class.php");
					$this->obj_receive = new ReceiveClass();
				}
				/**
			 	 * 获得随机的唯一收货地址编码
			 	 */
				$receive_last_id = $this->obj_receive->getReceiveLastId();
				if("" == $receive_last_id){
					$receive_last_id = 1;
				}else{
					$receive_last_id += 1;
				}
				$chars = array(
				"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
				"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
				"w", "x", "y", "z"
				);
				$random_string = Common::genRandomString($chars, 4);
				$this->_input["txtRcode"] = md5($receive_last_id.$random_string);
				$this->_input["member_id"] = $_SESSION['s_login']['id'];
				$this->obj_receive->addReceive($this->_input);
				$this->_input["txtReceiveId"] = $this->_input["txtRcode"];
			}
			$this->_input["txtBuyerId"] = $_SESSION['s_login']['id'];

			/**
			 * 拍卖出价记录
			 */
			if("0" == $this->_input["sell_type"]){
				if (!is_object($this->obj_product_bid)){
					require_once("bid.class.php");
					$this->obj_product_bid = new BidClass();
				}

				/**
				 * 判断是否使用代理出价
				 */
				$buy_price = $this->_input["min_price"];
				$pay_price = $this->_input["txtPayPrice"];
				if($buy_price < $pay_price){
					$this->_input["max_price"] = $pay_price;
				}

				/**
				 * 单件拍卖
				 */
				if($this->_input["p_storage"] == "1"){

					/**
					 * 更新出局出价记录状态
					 */
					$bid_product["p_code"] = $this->_input["txtPcode"];
					$agent_bid = $this->obj_product_bid->agentBid($bid_product);
					if(count($agent_bid) > 0){
						/*存在代理出价*/
						$agent_input["txtBuyerId"] = $agent_bid["bid_member_id"];
						$agent_input["txtPcode"] = $agent_bid["bid_p_code"];
						$agent_input["max_price"] = $agent_bid["bid_max_price"];
						$agent_input["min_price"] = $agent_bid["bid_price"];
						$agent_input["txtBuyNum"] = $agent_bid["bid_count"];
						$agent_input["txtReceiveId"] = $agent_bid["bid_receive_code"];
						$agent_input["bid_state"] = $agent_bid["bid_state"];

						/*更新出局出价记录状态*/
						$bid_out = $this->obj_product_bid->updateProductBidStateInCondition($bid_product);

						/*代理出价者出价信息*/
						$agent_last_bid = $agent_input;
						$user_last_bid = $this->_input;
						if("" != $this->_input["max_price"]){

							if($agent_input["max_price"] < $this->_input["max_price"]){


								for($i=0; (($buy_price+$i*$this->_input["step_price"]) <= $agent_input["max_price"]) || ((($buy_price+$i*$this->_input["step_price"]) > $agent_input["max_price"]) && ($agent_input["max_price"] + $this->_input["step_price"] > ($buy_price+$i*$this->_input["step_price"]))); $i++){
									$user_temp_bid = $user_last_bid;
									$this_min_price = $buy_price+($i)*$this->_input["step_price"];
									/*保存当前出价用户代理出价记录*/
									$user_temp_bid["max_price"] = "";
									if($user_last_bid["max_price"] <= $this_min_price){
										$user_temp_bid["bid_state"] = "1";
										$user_temp_bid["min_price"] = $user_last_bid["max_price"];
									}else{
										$user_temp_bid["bid_state"] = "0";
										$user_temp_bid["min_price"] = $this_min_price;
									}
									$user_temp_bid["bid_time"] = time() + $i;
									$user_bid_result = $this->obj_product_bid->saveProductBid($user_temp_bid);

									/*保存代理出价用户代理出价记录*/
									$agent_last_bid["max_price"] = "";
									if($agent_input["max_price"] <= $this_min_price){
										$agent_last_bid["bid_state"] = "0";
										$agent_last_bid["min_price"] = $agent_input["max_price"];
									}else{
										$agent_last_bid["bid_state"] = "0";
										$agent_last_bid["min_price"] = $this_min_price;
									}
									$agent_last_bid["bid_time"] = time() + $i + 1;
									$agent_bid_result = $this->obj_product_bid->saveProductBid($agent_last_bid);
								}


								if($user_temp_bid["bid_state"] == "0"){
									/*保存用户最高出价记录*/
									$user_this_bid = $this->_input;
									$user_this_bid["bid_state"] = "1";
									if($this->_input["max_price"] >= ($this_min_price + $this->_input["step_price"])){
										$user_this_bid["max_price"] = $this->_input["max_price"];
										$user_this_bid["min_price"] = $this_min_price + $this->_input["step_price"];
									}else{
										$user_this_bid["max_price"] = "";
										$user_this_bid["min_price"] = $this->_input["max_price"];
									}
									$user_this_bid["bid_time"] = time() + $i + 2;
									$user_bid_result = $this->obj_product_bid->saveProductBid($user_this_bid);

								}


								/*当前价格*/
								$cur_price = $user_this_bid["min_price"];

							}elseif($agent_input["max_price"] == $this->_input["max_price"]){

								for($i=0; (($buy_price+$i*$this->_input["step_price"]) <= $agent_input["max_price"]) || ((($buy_price+$i*$this->_input["step_price"]) > $agent_input["max_price"]) && ($agent_input["max_price"] + $this->_input["step_price"] > ($buy_price+$i*$this->_input["step_price"]))); $i++){
									$user_temp_bid = $user_last_bid;
									$this_min_price = $buy_price+($i)*$this->_input["step_price"];
									/*保存当前出价用户代理出价记录*/
									$user_temp_bid["max_price"] = "";
									if($user_last_bid["max_price"] <= $this_min_price){
										$user_temp_bid["bid_state"] = "0";
										$user_temp_bid["min_price"] = $user_last_bid["max_price"];
									}else{
										$user_temp_bid["bid_state"] = "0";
										$user_temp_bid["min_price"] = $this_min_price;
									}
									$user_temp_bid["bid_time"] = time() + $i;
									$user_bid_result = $this->obj_product_bid->saveProductBid($user_temp_bid);

									/*保存代理出价用户代理出价记录*/
									$agent_last_bid["max_price"] = "";
									if($agent_input["max_price"] <= $this_min_price){
										$agent_last_bid["bid_state"] = "1";
										$agent_last_bid["min_price"] = $agent_input["max_price"];
									}else{
										$agent_last_bid["bid_state"] = "0";
										$agent_last_bid["min_price"] = $this_min_price;
									}
									$agent_last_bid["bid_time"] = time() + $i + 1;
									$agent_bid_result = $this->obj_product_bid->saveProductBid($agent_last_bid);
								}


								/*当前价格*/
								$cur_price = $agent_last_bid["min_price"];

							}else{

								for($i=0; (($buy_price+$i*$this->_input["step_price"]) <= $this->_input["max_price"]) || ((($buy_price+$i*$this->_input["step_price"]) > $this->_input["max_price"]) && ($this->_input["max_price"] + $this->_input["step_price"] > ($buy_price+$i*$this->_input["step_price"]))); $i++){
									$user_temp_bid = $user_last_bid;
									$agent_temp_bid = $agent_last_bid;
									$this_min_price = $buy_price+($i)*$this->_input["step_price"];
									/*保存当前出价用户代理出价记录*/
									$user_temp_bid["max_price"] = "";
									if($user_last_bid["max_price"] <= $this_min_price){
										$user_temp_bid["bid_state"] = "0";
										$user_temp_bid["min_price"] = $user_last_bid["max_price"];
									}else{
										$user_temp_bid["bid_state"] = "0";
										$user_temp_bid["min_price"] = $this_min_price;
									}
									$user_temp_bid["bid_time"] = time() + $i;
									$user_bid_result = $this->obj_product_bid->saveProductBid($user_temp_bid);

									/*保存代理出价用户代理出价记录*/
									$agent_temp_bid["max_price"] = "";
									if($agent_input["max_price"] <= $this_min_price){
										$agent_temp_bid["bid_state"] = "1";
										$agent_temp_bid["min_price"] = $agent_input["max_price"];
										$agent_this_bid["min_price"] = $agent_temp_bid["min_price"];
									}elseif($user_last_bid["max_price"] <= $this_min_price){
										$agent_temp_bid["bid_state"] = "1";
										$agent_temp_bid["max_price"] = $agent_input["max_price"];
										$agent_temp_bid["min_price"] = $this_min_price;
										$agent_this_bid["min_price"] = $agent_temp_bid["min_price"];
									}else{
										$agent_temp_bid["bid_state"] = "0";
										$agent_temp_bid["min_price"] = $this_min_price;
									}
									$agent_temp_bid["bid_time"] = time() + $i + 1;
									$agent_bid_result = $this->obj_product_bid->saveProductBid($agent_temp_bid);
								}


								if($agent_temp_bid["bid_state"] == "0"){
									/*保存用户最高出价记录*/
									$agent_this_bid = $agent_last_bid;
									$agent_this_bid["bid_state"] = "1";
									if($agent_last_bid["max_price"] >= ($this_min_price + $this->_input["step_price"])){
										$agent_this_bid["max_price"] = $this->_input["max_price"];
										$agent_this_bid["min_price"] = $this_min_price + $this->_input["step_price"];
									}else{
										$agent_this_bid["max_price"] = "";
										$agent_this_bid["min_price"] = $this->_input["max_price"];
									}
									$agent_this_bid["bid_time"] = time() + $i + 2;
									$agent_bid_result = $this->obj_product_bid->saveProductBid($agent_this_bid);

								}

								/*当前价格*/
								$cur_price = $agent_this_bid["min_price"];

							}
						}else{
							if($agent_input["max_price"] < $buy_price){

								$agent_last_bid["bid_state"] = "0";
								$this->_input["bid_state"] = "1";

								/*保存代理出价用户代理出价记录*/
								$agent_last_bid["max_price"] = "";
								$agent_last_bid["min_price"] = $agent_input["max_price"];
								$bid_result = $this->obj_product_bid->saveProductBid($agent_last_bid);

								/*保存用户此次出价记录*/
								$bid_result = $this->obj_product_bid->saveProductBid($this->_input);

								/*当前价格*/
								$cur_price = $buy_price;

							}elseif($agent_input["max_price"] == $buy_price){

								$agent_last_bid["bid_state"] = "1";
								$this->_input["bid_state"] = "0";

								/*保存用户此次出价记录*/
								$bid_result = $this->obj_product_bid->saveProductBid($this->_input);
								/*保存代理出价用户代理出价记录*/
								$agent_last_bid["max_price"] = "";
								$agent_last_bid["min_price"] = $buy_price;
								$bid_result = $this->obj_product_bid->saveProductBid($agent_last_bid);

								/*当前价格*/
								$cur_price = $buy_price;

							}else{

								$agent_last_bid["bid_state"] = "0";
								$this->_input["bid_state"] = "0";

								/*保存用户此次出价记录*/
								$bid_result = $this->obj_product_bid->saveProductBid($this->_input);
								/*保存代理出价用户代理出价记录*/
								$agent_last_bid["max_price"] = "";
								$agent_last_bid["min_price"] = $buy_price;
								$bid_result = $this->obj_product_bid->saveProductBid($agent_last_bid);

								/*保存代理出价用户领先出价记录*/
								$agent_this_bid = $agent_input;
								$agent_this_bid["bid_state"] = "1";
								if($agent_input["max_price"] > ($buy_price + $this->_input["step_price"])){
									$agent_this_bid["max_price"] = $agent_input["max_price"];
									$agent_this_bid["min_price"] = $buy_price + $this->_input["step_price"];
								}else{
									$agent_this_bid["max_price"] = "";
									$agent_this_bid["min_price"] = $agent_input["max_price"];
								}
								$bid_result = $this->obj_product_bid->saveProductBid($agent_this_bid);

								/*当前价格*/
								$cur_price = $agent_this_bid["min_price"];

							}

						}

						/**
						 * 更新拍卖商品当前价格
						 */
						$product_cur["p_code"] = $this->_input["txtPcode"];
						$product_cur["cur_price"] = $cur_price;
						$update_product_cur_price = $this->obj_product->updateProductCurPrice($product_cur);

					}else{
						$bid_out = $this->obj_product_bid->updateProductBidStateInCondition($bid_product);

						$this->_input["bid_state"] = 1;
						$bid_result = $this->obj_product_bid->saveProductBid($this->_input);
						/**
						 * 更新拍卖商品当前价格
						 */
						$product_cur["p_code"] = $this->_input["txtPcode"];
						$product_cur["cur_price"] = $this->_input["min_price"];
						$update_product_cur_price = $this->obj_product->updateProductCurPrice($product_cur);
					}

				}else{
					/**
					 * 多件拍卖
					 */
					$count = $this->_input["txtBuyNum"];
					$p_storage = $this->_input["p_storage"];

					$bid_product["p_code"] = $this->_input["txtPcode"];

					/*记录竞拍信息*/
					$bid_array = array();
					$bid_array['txtBuyerId'] = $_SESSION['s_login']['id'];/*竞拍会员*/
					$bid_array['txtPcode'] = $this->_input["txtPcode"];/*竞拍商品*/
					$bid_array['min_price'] = $this->_input["txtPayPrice"];/*竞拍单价*/
					$bid_array['txtBuyNum'] = $count;/*购买数量*/
					$bid_array['txtReceiveId'] = $this->_input["txtReceiveId"];/*收费地址编号*/
					$bid_array['bid_state'] = 1;
					$this->obj_product_bid->saveProductBid($bid_array);
					unset($bid_array);
					/**
					 * 取出所有竞拍该商品处于领先状态的竞拍信息
					 */
					$condition_bid['p_code'] = $this->_input["txtPcode"];
					$condition_bid['bid_state'] = 1;
					$condition_bid['order'] = 2;
					$bid_array = $this->obj_product_bid->getProductBidList($condition_bid,$page);
					
					/**
					 * 整理竞拍信息 商品总数为$p_storage
					 */
					if (is_array($bid_array)){
						$line = 0;
						$array = array();
						foreach ($bid_array as $k => $v){
							$line+=$v['bid_count'];
							if ($line<=$p_storage){
								$array[] = $v;
							}else {
								break;
							}
						}
					}
					/**
					 * 判断最后一位是否是竞拍商品数量不足，如果是则发站内信
					 */
					if (($line-$p_storage)<$bid_array[count($array)]['bid_count']){/*则说明最后一位是购买数量不足,并且该竞拍信息的状态不变化*/
						/**
						 * 网站提醒操作
						 */
						$condition = '';
						$condition['p_code'] = $this->_input['txtPcode'];
						$condition['state'] = "none";
						$product_array = $this->obj_product->getProductList($condition, &$obj_page);/*取商品信息*/
						$condition['id'] = $bid_array[count($array)]['bid_member_id'];
						$member_array = $this->obj_member->getMemberInfo($condition);/*取会员信息*/

						$value_array = array();
						$value_array['username'] = $member_array['login_name'];
						$value_array['product_name'] = $product_array[0]['p_name'];
						$this->obj_remind->setMessageOrMail('buyer_bid_above_notice','bid_above_notice',$value_array,$member_array['login_name'],$this->_configinfo);//当我的出价被超过时，请通知我
						
						$array[count($array)] = $bid_array[count($array)];
					}
					/*取需要把状态变为出局的竞拍信息*/
					
					$array = @array_diff_key($bid_array,$array);
					if (is_array($array)){
						foreach ($array as $k => $v){
							$input_param = array();
							$input_param['bid_state'] = 0;
							$input_param['bid_id'] = $v['bid_id'];
							$this->obj_product_bid->updateProductBidState($input_param);
						}
					}
				}
			}else{

				/**
			 	 * 获得随机的唯一商品订单编码
				 */
				$product_order_last_id = $this->obj_product->getProductOrderLastId();
				if("" == $product_order_last_id){
					$product_order_last_id = 1;
				}else{
					$product_order_last_id += 1;
				}
				$chars = array(
				"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
				"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
				"w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G",
				"H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
				"S", "T", "U", "V", "W", "X", "Y", "Z"
				);
				$random_string = Common::genRandomString($chars, 4);
				$this->_input["txtSPcode"] = md5($product_order_last_id.$random_string);
				/**
				 * 判断是否团购，对团购商品的处理
				 */
				$this->_input["sp_state"] = 0;
				if("2" == $this->_input["sell_type"]){
					if(($this->_input["p_sold_num"]+$this->_input["txtBuyNum"]) < $this->_input["group_mincount"]){
						$this->_input["sp_state"] = 4;
					}else{
						$change_state["sp_state"] = 0;
						$change_state["p_code"] = $this->_input["txtPcode"];
						$change_state["sp_old_state"] = 4;
						$this->obj_product_order->updateProductOrderInCondition($change_state);
					}

				}


				/**
				 * 保存商品订单
				 */
				if (!is_object($this->obj_product_order)){
					require_once("order.class.php");
					$this->obj_product_order = new ProductOrderClass();
				}
				$result = $this->obj_product_order->saveProductOrder($this->_input);

				/**
				 * 更新商品售出数量
				 */
				$update_product_sold_num = $this->obj_product->updateProductSoldCount($this->_input);
				
				/**
				 * 网站提醒操作
				 */
				/**
				 * 取商品信息
				 */
				$condition['p_code'] = $this->_input['txtPcode'];
				$condition['state'] = "none";
				$product_array = $this->obj_product->getProductList($condition, &$obj_page);

				$condition['id'] = $product_array[0]['member_id'];
				$member_array = $this->obj_member->getMemberInfo($condition);

				if ($this->_input['leaveword'] != ''){
					/**
					 * 添加留言
					 */
					require_once("productmessage.class.php");
					$obj_message = new ProductMessageClass();
					$member_array = array();
					$member_array['MemberName'] = $_SESSION['s_login']['name'];
					$member_array['txtMessage'] = $this->_input['leaveword'];
					$member_array['hideproductID'] = $product_array[0]['p_id'];
					$member_array['pid'] = $this->_input['txtPcode'];
					$member_array['hidememberID'] = $product_array[0]['member_id'];
					$member_array['anonymous'] = $this->_input['anonymous'];
					$obj_message->addMessage($member_array);					
				}

				$value_array = array();
				$value_array['username'] = $member_array['login_name'];
				$value_array['product_name'] = $product_array[0]['p_name'];
				$this->obj_remind->setMessageOrMail('sale_buyer_to_succ','buyer_to_succ',$value_array,$member_array['login_name'],$this->_configinfo);//当买家提醒我完成交易时，请通知我

				$value_array = array();
				$value_array['username'] = $_SESSION['s_login']['name'];
				$value_array['product_name'] = $product_array[0]['p_name'];
				$this->obj_remind->setMessageOrMail('buyer_buy_succ_notice','buyer_buy_succ_notice',$value_array,$_SESSION['s_login']['name'],$this->_configinfo);//当我成功购得一口价的宝贝时，请通知我
			}
			$this->redirectPath("succ","member/own_order.php?action=bought","商品购买成功！");
		}
	}

	/**
	 * 比较产品
	 *
	 */
	function _compareproduct(){
		//		print_r($this->_input['pcode']);exit;
		$pcode_array = explode("_",$this->_input['pcode']);
		$this->setCompare($pcode_array);
		header("location:product.php?action=compareresult");
	}
	function _compareproductresult(){
		$compare_cookie = $this->getCookies('compare');
		if("" != $compare_cookie){
			$cookie_array = explode("|", $compare_cookie);
			foreach ($cookie_array as $key => $value){
				$obj_condition[pcodes][$key] = $value;

			}
			$product_array = $this->obj_product->getProductList($obj_condition, $obj_page);

			/**
			 * 取得商品属性
			 */
			require_once("attribute.class.php");
			$obj_product_attribute = new AttributeClass();


			$product_attribute_compare = array();

			/**
		 	* 得到店主信息
			*/
			$product_array = $this->obj_member->getSomeMember($product_array,'member_id','member_id,login_name as shopmaster');

			for($i=0;$i<count($product_array);$i++){

				/**
				 * 取商品属性
				 */
				$pcid = $product_array[$i]['pc_id'];
				$product_attribute = $obj_product_attribute->getAttributeList($pcid);
				if(is_array($product_attribute_compare)){
					if(!in_array($product_attribute,$product_attribute_compare)){
						array_push($product_attribute_compare, $product_attribute);
					}
				}


				$product_attribute_content[$i] = $obj_product_attribute->getAttributeWithContentList($pcid);

				$p_id = $product_array[$i]['p_code'];
				$attribute_condition_str = " and p_id = '" . $p_id . "'";
				$product_have_attribute[$i] = $this->obj_product->getProductAttribute($attribute_condition_str, $obj_page);


				$j=0;
				$pac_attribute = array();
				if(is_array($product_have_attribute[$i])){
					foreach ($product_have_attribute[$i] as $key => $value){
						$ac_content = explode(',', $value[pac_content]);
						foreach ($ac_content as $k => $v){
							$pac_attribute[$j] = $v;
							$j++;
						}
					}
				}
				if(is_array($product_attribute_content[$i])){
					foreach ($product_attribute_content[$i] as $key => $value){
						foreach ($value as $k => $v){
							if(is_array($pac_attribute) && in_array($v[ac_id], $pac_attribute)){
								$product_attribute_content[$i][$key][$k][ischecked] = 1;
							}
						}
					}
				}

				$left_time = $product_array[$i]['p_end_time'] - time();
				$product_array[$i]['left_days'] = intval($left_time / (24*60*60));
				$product_array[$i]['left_hours'] = intval(($left_time % (24*60*60)) / (60*60));
				$product_array[$i]['left_minutes'] = intval((($left_time % (60*60))) / 60);
				$product_array[$i]['product_type'] = $this->_b_config['p_type'][$product_array[$i]['p_type']];
			}
		}

		$this->output("product_compare", $product_array);
		$this->output("product_attribute_compare", $product_attribute_compare);
		$this->output("product_attribute_content", $product_attribute_content);
		$this->output("product_have_attribute", $pac_attribute);
		$this->showpage("product.compare");
	}
	/**
	 * 移除对比商品
	 *
	 */
	function _compareremove(){
		$pcode = $this->_input['pid'];
		$this->unsetCompare($pcode);
		header("location:product.php?action=compareresult");
	}
	/**
	 * 列出 浏览过的宝贝中的 商品
	 * 
	 */
	function _reviewedproduct()
	{
		$str = $this->getCookies('c_product_viewed');
		if ("" != $str) {
			$reviewed_product = $this->getReveiwedProduct($str);
		}

		$line = $str;
		$line = str_replace('|','_',$line);
		$this->output("reviewed_code", $line);
		$this->output("reviewed_product", $reviewed_product);
	}
	/**
	 * 清除 浏览过的宝贝中的 记录
	 * 
	 */
	function _cleanreviewedproduct()
	{
		$this->setCookies("c_product_viewed", '');
		$this->redirectPath("refer","","");
	}
	/**
	 * 买过此类商品的人还买过的商品
	 * 
	 */
	function _boughtproduct()
	{
		if ($this->_input['pcid'] != ''){
			$pcid = $this->_input['pcid'];//商品类别ID
			$bought_array = $this->obj_product->getBoughtProduct($pcid);//还买过的商品列表
			$this->output("buyed_array", $bought_array);
		}
	}


	/**
	 * 把要进行对比的产品的产品号放到COOKIE中保存
	 *
	 * @param var[] $pcode
	 * @return boolean
	 */
	function setCompare($pcode){
		$new_pcode = "";
		$compare_cookie = $this->getCookies('compare');
		if("" != $compare_cookie){
			$cookie_pcode = $compare_cookie;
			$cookie_array = explode("|", $compare_cookie);
		}else{
			$cookie_array=array();
		}

		if (is_array($pcode)){
			foreach ($pcode as $k=>$v){
				if(!in_array($v, $cookie_array)){
					$cookie_pcode .= "|" . $v;
				}
			}
		}else{
			if(!in_array($pcode, $cookie_array)){
				$cookie_pcode .= "|" . $pcode;
			}
		}
		$this->setCookies("compare", $cookie_pcode);
		return true;
	}
	/**
	 * 在COOKIE中移除对比中的商品
	 *
	 * @param string $pcode
	 * @return boolean
	 */
	function unsetCompare($pcode){
		$new_pcode = "";
		$compare_cookie = $this->getCookies('compare');
		if("" != $compare_cookie){
			$cookie_pcode = $compare_cookie;
			$cookie_array = explode("|", $compare_cookie);
		}else{
			$cookie_array=array();
		}

		if ("" != $pcode){
			foreach ($cookie_array as $k=>$v){
				if($pcode == $v){
					array_splice($cookie_array, $k, 1);
				}else{
					$cookie_new_pcode .= "|" . $v;
				}

			}
		}
		$this->setCookies("compare", $cookie_new_pcode);
		return true;
	}
	/**
	 * 获得 cookie 中的浏览过的商品信息列表
	 * @param  str $str 商品货号
	 * @return array 返回商品信息列表
	 */
	function getReveiwedProduct($str)
	{
		$array = array();
		$array = @explode('|',$str);

		foreach ($array as $key => $value){
			$product_arr[$key] = $this->obj_product->getProductRow($value);
			if ($key == 2){ break; }
		}
		return $product_arr;
	}
	/**
	 * 把浏览过的产品的产品号放到COOKIE中保存
	 *
	 * @param var[] $pcode
	 * @return boolean
	 */
	function setReviewed($pcode){

		$str = $this->getCookies('c_product_viewed');
		if("" != $str){
			$cookie_array = @explode("|", trim($str,'|'));
			if (count($cookie_array) >= 4){
				array_pop($cookie_array);
				$cookie_pcode = @implode('|',$cookie_array);
			}else{
				$cookie_pcode = @implode('|',$cookie_array);
			}
		}else{
			$cookie_array=array();
		}

		if (!@in_array($pcode,$cookie_array)){/*如果产品在cookie里已有，则不记录*/
			if (count($cookie_array) == 0) {
				$cookie_pcode = $pcode;
			}else {
				$cookie_pcode =  $pcode."|".$cookie_pcode;
			}
		}

		$this->setCookies("c_product_viewed", $cookie_pcode);
		return true;
	}
	
	/**
	 * AJ 判断验证码是否正确
	 */
	function _check_code(){
		$code = $this->_input['checkcode'];
		if (strtoupper($code) == strtoupper($_SESSION['seccode'])){
			echo 1;/*正确*/
		}else {
			echo 2;/*错误*/
		}
	}
}

$product = new ShowProduct();
$product->main();
unset($product);
?>